﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using NMemcached.Client;

namespace NMemcached.Client.Test
{
    [TestClass]
    public class ComponentTests
    {
        public const string CompressionTarget = "Today a young man on acid realized that all matter is merely energy condensed to a slow vibration, that we are all one consciousness experiencing itself subjectively, there is no such thing as death, life is only a dream, and we are the imagination of ourselves. Heres Tom with the Weather. --Bill Hicks";

        [TestMethod]
        public void GZipTest()
        {
            ICompressor compressor = new GZipCompressor();

            string result = this.CompressorTest(compressor);

            Assert.AreEqual(ComponentTests.CompressionTarget, result);
        }

        [TestMethod]
        public void DeflateTest()
        {
            ICompressor compressor = new DeflateCompressor();

            string result = this.CompressorTest(compressor);

            Assert.AreEqual(ComponentTests.CompressionTarget, result);
        }

        private string CompressorTest(ICompressor compressor)
        {
            byte[] targetBytes = Encoding.UTF8.GetBytes(ComponentTests.CompressionTarget);

            byte[] compressedBytes = compressor.Compress(targetBytes);

            byte[] decompressedBytes = compressor.Decompress(compressedBytes);

            string resultString = Encoding.UTF8.GetString(decompressedBytes);

            return resultString;
        }
    }
}
